import java.util.*;
class Sort implements Comparable {
    double d=0;
    Sort (double d) {
        this.d=d;
    }
    @Override
    public int compareTo(Object b) {
        Sort st=(Sort) b;
        if((this.d-st.d)==0) {
            return -1;
        }
        else {
            return (int) ((this.d - st.d) * 1000);
        }
    }
}
class U {
    String name="";
    double speed,capacity;
    U(String name,double speed,double capacity) {
        this.name=name;
        this.capacity=capacity;
        this.speed=speed;
    }
}
public class PriceSort {
    public static void main(String args[ ]) {
        TreeMap<Sort,U>  treemap= new TreeMap<Sort,U>();
        String name[]={"A","B","C","D","E","F","G","H","I","J"};
        double speed[]={111,100,101,345,213,433,565,333,454,454};
        double capacity[]={4,10,32,64,128,34,68,120,112,1024};
        U u[]=new U[10];
        for(int k=0;k<u.length;k++) {
            u[k]=new U(name[k],speed[k],capacity[k]);
        }
        Sort key[]=new Sort[10] ;
        for(int k=0;k<key.length;k++) {
            key[k]=new Sort(u[k].speed);
        }
        for(int k=0;k<u.length;k++) {
            treemap.put(key[k],u[k]);
        }
        System.out.println("按speed排序:");
        Collection<U> collection=treemap.values();
        Iterator<U> iter=collection.iterator();
        while(iter.hasNext()) {
            U stu=iter.next();
            System.out.println("品牌"+stu.name+"speed："+stu.speed);
        }
        treemap.clear();
        for(int k=0;k<key.length;k++) {
            key[k]=new Sort(u[k].capacity);
        }
        for(int k=0;k<u.length;k++) {
            treemap.put(key[k],u[k]);
        }
        System.out.println("按capacity排序:");
        collection=treemap.values();
        iter=collection.iterator();
        while(iter.hasNext()) {
            U stu=(U)iter.next();
            System.out.println("品牌"+stu.name+" capacity ："+stu.capacity);
        }
    }
}
